﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScriptCompare
{
    public static class Extensions
    {
        public static IList<ScriptLine> GetRange(this IList<ScriptLine> source, int startIndex, int rows)
        {
            // Argument check
            if (source == null)
                throw new ArgumentNullException("source");

            // Index check
            if (startIndex < 0)
                throw new IndexOutOfRangeException("Start index must be greater than zero.");
            else if ((rows + startIndex) >= source.Count)
                throw new IndexOutOfRangeException("Number of rows requested, from starting index, exceeds the length of the array.");

            List<ScriptLine> rangeList = new List<ScriptLine>();

            for (int itr = 0; itr < rows; itr++)
            {
                rangeList.Add(source[startIndex + itr]);
            }

            return (rangeList);
        }

        public static IList<ScriptLine> LinesAfter(this IList<ScriptLine> source, int startIndex)
        {
            return (source.GetRange(startIndex, (source.Count - 1) - startIndex));
        }

        public static void Swap(this IList<ScriptLine> source, int a, int b)
        {
            // Get the item at 'a'
            ScriptLine aLine = source[a];

            // Set position 'a'
            source[a] = source[b];

            // Set position 'b'
            source[b] = aLine;
        }
    }
}
